package controller;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import service.StationService;
import service.TrainService;

import model.Station;
import model.Train;

@ManagedBean
@SessionScoped
public class AutoCompleteController {
	
	@EJB
	private StationService stationService;
	
	@EJB
	private TrainService trainService;
	
	public List<String> completeStation(String query) {  
        List<String> suggestions = new ArrayList<String>();  
          
        for(Station s : stationService.findAll()) {  
            if(s.getStationName().startsWith(query))  
                suggestions.add(s.getStationName());   
        }  
        return suggestions;  
    }  
	
	public List<String> completeTrain(String query) {  
        List<String> suggestions = new ArrayList<String>();  
          
        for(Train t : trainService.findAll()) {  
            if(("" + t.getTrainNumber()).startsWith(query))  
                suggestions.add("" + t.getTrainNumber());  
        }  
          
        return suggestions;  
    }  
}
